package com.ruoyi.web.controller.quantization;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quantization.domain.SysMorality;
import com.ruoyi.quantization.service.ISysMoralityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品德Controller
 * 
 * @author ruoyi
 * @date 2024-10-02
 */
@RestController
@RequestMapping("/system/morality")
public class SysMoralityController extends BaseController
{
    @Autowired
    private ISysMoralityService sysMoralityService;

    /**
     * 查询品德列表
     */
    @PreAuthorize("@ss.hasPermi('system:morality:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMorality sysMorality)
    {
        startPage();
        List<SysMorality> list = sysMoralityService.selectSysMoralityList(sysMorality);
        return getDataTable(list);
    }



    /**
     * 导出品德列表
     */
    @PreAuthorize("@ss.hasPermi('system:morality:export')")
    @Log(title = "品德", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMorality sysMorality)
    {
        List<SysMorality> list = sysMoralityService.selectSysMoralityList(sysMorality);
        ExcelUtil<SysMorality> util = new ExcelUtil<SysMorality>(SysMorality.class);
        util.exportExcel(response, list, "品德数据");
    }

    /**
     * 获取品德详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:morality:query')")
    @GetMapping(value = "/{moralityId}")
    public AjaxResult getInfo(@PathVariable("moralityId") Long moralityId)
    {
        return success(sysMoralityService.selectSysMoralityByMoralityId(moralityId));
    }

    /**
     * 新增品德
     */
    @PreAuthorize("@ss.hasPermi('system:morality:add')")
    @Log(title = "品德", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMorality sysMorality)
    {
        return toAjax(sysMoralityService.insertSysMorality(sysMorality));
    }

    /**
     * 修改品德
     */
    @PreAuthorize("@ss.hasPermi('system:morality:edit')")
    @Log(title = "品德", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMorality sysMorality)
    {
        return toAjax(sysMoralityService.updateSysMorality(sysMorality));
    }

    /**
     * 删除品德
     */
    @PreAuthorize("@ss.hasPermi('system:morality:remove')")
    @Log(title = "品德", businessType = BusinessType.DELETE)
	@DeleteMapping("/{moralityIds}")
    public AjaxResult remove(@PathVariable Long[] moralityIds)
    {
        return toAjax(sysMoralityService.deleteSysMoralityByMoralityIds(moralityIds));
    }
}
